package com.pgytesting.secondhandcar.controller.admin;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import com.pgytesting.secondhandcar.model.ExamineInformation;
import com.pgytesting.secondhandcar.model.OrderName;
import com.pgytesting.secondhandcar.model.ReviewInformation;
import com.pgytesting.secondhandcar.service.OrderNameService;
import com.pgytesting.secondhandcar.service.ReviewInformationService;
import com.pgytesting.secondhandcar.vo.Parameters;
import com.pgytesting.secondhandcar.vo.ResponseMessage;

import lombok.extern.slf4j.Slf4j;


@Slf4j
@RestController
@RequestMapping("/admin/riskControlExamine")
public class RiskControlExamineController {

	@Autowired
	private OrderNameService orderNameService;
	@Autowired
	private ReviewInformationService reviewInformationService;
	
	
	/**
	 * 获取风控审核材料信息列表
	 * @param orderName
	 * @return
	 */
	@RequestMapping(value = "/getRiskControlList",method = RequestMethod.POST)
	public ResponseMessage getRiskControlList() {
		try {
			OrderName orderName = new OrderName();
			orderName.setOrderStatus(Parameters.ORDER_25001);
			orderName.setStatus(0);
			return ResponseMessage.successResponse(orderNameService.queryAll(orderName));			
		} catch (Exception e) {
			e.printStackTrace();
			return ResponseMessage.errorResponse("获取贷款列表出现异常");
		}
	}
	
	/**
	 * 风控审核通过
	 * @param orderName
	 * @return
	 */
	@RequestMapping(value = "/riskControlReviewAdopt",method = RequestMethod.POST)
	public ResponseMessage riskControlReviewAdopt(@RequestBody OrderName orderName) {
		try {
			return reviewInformationService.riskControlPreliminaryExamination(orderName.getId(),Parameters.ORDER_25006,0);
		} catch (Exception e) {
			e.printStackTrace();
			return ResponseMessage.errorResponse("风控审核通过出现异常");
		}
	}
	
	/**
	 * 风控审核拒绝
	 * @param orderName
	 * @return
	 */
	@RequestMapping(value = "/riskControlReviewRefuse",method = RequestMethod.POST)
	public ResponseMessage riskControlReviewRefuse(@RequestBody OrderName orderName) {
		try {
			return reviewInformationService.riskControlPreliminaryExamination(orderName.getId(),Parameters.ORDER_25002,1);
		} catch (Exception e) {
			e.printStackTrace();
			return ResponseMessage.errorResponse("风控审核拒绝出现异常");
		}
	}
	
	/**
	 * 风控审核补件
	 * @param orderName
	 * @return
	 */
	@RequestMapping(value = "/riskControlReviewSupplement",method = RequestMethod.POST)
	public ResponseMessage riskControlReviewSupplement(@RequestBody OrderName orderName) {
		try {
			return reviewInformationService.riskControlPreliminaryExamination(orderName.getId(),Parameters.ORDER_25003,3);
		} catch (Exception e) {
			e.printStackTrace();
			return ResponseMessage.errorResponse("风控审核补件出现异常");
		}
	}
	
	/**
	 * 风控审核共借
	 * @param orderName
	 * @return
	 */
	@RequestMapping(value = "/riskControlReviewJointLending",method = RequestMethod.POST)
	public ResponseMessage riskControlReviewJointLending(@RequestBody OrderName orderName) {
		try {
			return reviewInformationService.riskControlPreliminaryExamination(orderName.getId(),Parameters.ORDER_25004,5);	
		} catch (Exception e) {
			e.printStackTrace();
			return ResponseMessage.errorResponse("风控审核共借出现异常");
		}
	}
	
	/**
	 * 风控审核取消共借
	 * @param orderName
	 * @return
	 */
	@RequestMapping(value = "/riskControlReviewCancelJointLending",method = RequestMethod.POST)
	public ResponseMessage riskControlReviewCancelJointLending(@RequestBody OrderName orderName) {
		try {
			return reviewInformationService.riskControlPreliminaryExamination(orderName.getId(),Parameters.ORDER_25005,6);
		} catch (Exception e) {
			e.printStackTrace();
			return ResponseMessage.errorResponse("风控审核取消共借出现异常");
		}
	}
	
	/**
	 * 风控终审通过
	 * @param orderName
	 * @return
	 */
	@RequestMapping(value = "/riskControlFinalJudgmentAdopt",method = RequestMethod.POST)
	public ResponseMessage riskControlFinalJudgmentAdopt(@RequestBody OrderName orderName) {
		try {
			reviewInformationService.riskControlFinalJudgment(orderName.getId(),Parameters.ORDER_26001,0);
			return ResponseMessage.successResponse("风控终审通过成功");			
		} catch (Exception e) {
			e.printStackTrace();
			return ResponseMessage.errorResponse("风控终审通过出现异常");
		}
	}
	
	/**
	 * 风控终审拒绝
	 * @param orderName
	 * @return
	 */
	@RequestMapping(value = "/riskControlFinalJudgmentRefuse",method = RequestMethod.POST)
	public ResponseMessage riskControlFinalJudgmentRefuse(@RequestBody OrderName orderName) {
		try {
			reviewInformationService.riskControlFinalJudgment(orderName.getId(),Parameters.ORDER_25007,1);
			return ResponseMessage.successResponse("风控终审拒绝成功");			
		} catch (Exception e) {
			e.printStackTrace();
			return ResponseMessage.errorResponse("风控终审拒绝出现异常");
		}
	}
	
	/**
	 * 风控终审驳回
	 * @param orderName
	 * @return
	 */
	@RequestMapping(value = "/riskControlFinalJudgmentRebut",method = RequestMethod.POST)
	public ResponseMessage riskControlFinalJudgmentRebut(@RequestBody OrderName orderName) {
		try {
			reviewInformationService.riskControlFinalJudgment(orderName.getId(),Parameters.ORDER_25008,2);
			return ResponseMessage.successResponse("风控终审驳回成功");			
		} catch (Exception e) {
			e.printStackTrace();
			return ResponseMessage.errorResponse("风控终审驳回出现异常");
		}
	}
}
